@echo off
echo ========================================
echo 完整的 HarmonyOS 构建流程
echo ========================================
echo.

echo 0. 安装最新的 Ionic CLI...
call npm uninstall -g ionic
call npm install -g @ionic/cli
echo ✅ Ionic CLI 更新完成

echo.
echo 1. 构建 Ionic 项目...
call npm run ionic:build
if %errorlevel% neq 0 (
    echo ❌ Ionic 构建失败，尝试备用方法...
    call npm run build
    if %errorlevel% neq 0 (
        echo ❌ 构建失败
        pause
        exit /b 1
    )
)
echo ✅ Ionic 构建完成

echo.
echo 2. 复制文件到 HarmonyOS 项目...
if exist "ohos\entry\src\main\resources\rawfile\ionic" (
    rmdir /s /q "ohos\entry\src\main\resources\rawfile\ionic"
)
mkdir "ohos\entry\src\main\resources\rawfile\ionic"
xcopy "dist\*" "ohos\entry\src\main\resources\rawfile\ionic\" /E /Y
if %errorlevel% neq 0 (
    echo ❌ 文件复制失败
    pause
    exit /b 1
)
echo ✅ 文件复制完成

echo.
echo 3. 检查 DevEco Studio...
if exist "C:\Program Files\Huawei\DevEco Studio" (
    echo ✅ 找到 DevEco Studio
    echo 请使用 DevEco Studio 打开项目: %~dp0ohos
) else (
    echo ❌ 未找到 DevEco Studio
    echo 请先安装 DevEco Studio 4.0+
)

echo.
echo ========================================
echo 构建流程完成
echo ========================================
pause